	.text            # Text-Segment
	.globl dot32x16  # Export Symbol

# This implementation assumes a little endian machine
# (storing the lower 32 bits in v0 and the higher 32 bits
# in the v1 register as result)
	
# extern int64_t dot32x16(
# a0: int n,
# a1: const int32_t x[],
# a2: const int16_t y[]);
	.set reorder
	.ent dot32x16
dot32x16:
	mtlo  $zero              # LO = 0;
	mthi  $zero              # HI = 0;
	beqz  $a0, .L_loopEnd    # if (a0==0) goto .L_loopEnd;
.L_loopStart:
	lh    $t2, 0($a2)        # t2 = *(int16_t*)(a2+0);
	lw    $t1, 0($a1)        # t1 = *(int32_t*)(a1+0);
	addiu $a0, $a0, -1       # a0--;
	addiu $a2, $a2,  2       # a2+=2;
	addiu $a1, $a1,  4       # a1+=4;
	madd  $t1, $t2           # HI::LO += t1*t2;
	bnez  $a0, .L_loopStart  # if (a0!=0) goto .L_loopStart;
.L_loopEnd:
	mflo  $v0                # v0 = LO;
	mfhi  $v1                # v1 = HI;
	jr    $ra                # goto ra (Ruecksprungadresse);
	.end dot32x16
